﻿using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.Core.Metadata.FormElement;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Validation;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Core.Permission;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.K3.SCM.ServiceHelper;
using Kingdee.K3.BD.ServiceHelper;
using Kingdee.BOS.Core;
using Kingdee.BOS.KDThread;
using Kingdee.BOS.Resource;
using Kingdee.BOS;
using Kingdee.BOS.JSON;
using Kingdee.K3.Core.BD.ServiceArgs;
using Kingdee.K3.Core.BD;
using Kingdee.K3.Core.SCM.Args;
using Kingdee.K3.Core.MFG.ENG.ParamOption;
using Kingdee.K3.FIN.App.Core.Match.Object;
using Kingdee.K3.Core.MFG.ENG.BomExpand;
using System.Data;
using Kingdee.BOS.Core.Metadata.BusinessService;
using static Kingdee.K3.FIN.Core.Object.AP_Matck;
using Kingdee.BOS.Log;

namespace RK.FormPlugin.GFT
{
    [Description("GFT:配套材料采购申请功能_扩展"), HotUpdate]
    public class DzAssortReqEdit : AbstractDynamicFormPlugIn
    {
        //页页初始化
        public override void OnInitialize(InitializeEventArgs e)
        {
            base.OnInitialize(e);
            this.bShowAssortResult = false;
            this.ShowAssortCalaGrid(this.bShowAssortResult);
            this._progressBar = this.View.GetControl<ProgressBar>("FProgressBar");
            this._processRate = 0;
            this.View.GetControl<EntryGrid>("FAssortResult").SetFireDoubleClickEvent(true);
        }
        //模型层数据包创建完毕
        public override void AfterCreateModelData(EventArgs e)
        {
            this.Model.SetValue("FApplicationOrgId", base.Context.CurrentOrganizationInfo.ID);
            base.AfterCreateModelData(e);
        }

        [Obsolete]
        public override void BeforeDoOperation(BeforeDoOperationEventArgs e)
        {
            base.BeforeDoOperation(e);
            string key;
            switch (key = e.Operation.FormOperation.Operation.ToUpperInvariant())
            {
                case "SELECTDATA":
                    this.GetSalOrderInfo();
                    this.bChkSupplyOrgBom = true;
                    return;
                case "SELECTPREDICT":
                    this.GetPredictInfo();
                    this.bChkSupplyOrgBom = false;
                    return;
                case "SELECTPRODUCE":
                    this.GetProduceInfo();
                    this.bChkSupplyOrgBom = false;
                    return;
                case "SELECTPLAN":
                    this.GetPlanInfo();
                    this.bChkSupplyOrgBom = false;
                    return;
                case "SELECTOUTSOURCING":
                    this.GetOutsourcingInfo();
                    this.bChkSupplyOrgBom = false;
                    return;
                case "SELECTBOM":
                    this.GetBOMInfo();
                    this.bChkSupplyOrgBom = false;
                    return;
                case "ASSORTCALCULATION":
                    if (this.View.Model.GetValue("FApplicationOrgId") == null)
                    {
                        this.View.ShowErrMessage("请先选择申请组织");
                        return;
                    }
                    if (this.View.Model.GetEntryRowCount("FSummaryData") <= 0)
                    {
                        this.View.ShowErrMessage("请先选择需要进行配套材料申请的销售订单或BOM");
                        return;
                    }
                    if (this.View.Model.GetEntryRowCount("FAssortResult") > 0)
                    {
                        this.View.Model.DeleteEntryData("FAssortResult");
                    }
                    this.ShowAssortCalaGrid(true);
                    this.ShowAssortResult();
                    return;
                case "GENERATEREQS":
                    {
                        if (this.View.Model.GetEntryRowCount("FAssortResult") <= 0)
                        {
                            return;
                        }
                        if (!(this.View.Model.GetValue("FApplicationOrgId") is DynamicObject) || Convert.ToInt64((this.View.Model.GetValue("FApplicationOrgId") as DynamicObject)["Id"]) <= 0L)
                        {
                            this.View.ShowErrMessage("请先选择申请组织");
                            return;
                        }
                        bool flag = false;
                        List<DynamicObject> list = this.GenerateReqs(base.Context, ref flag);
                        if (!flag)
                        {
                            return;
                        }
                        if (list == null || list.Count <= 0)
                        {
                            return;
                        }
                        this.GetPriceFromPriceList(list);
                        FormMetadata formMetaData = MetaDataServiceHelper.GetFormMetaData(base.Context, "PUR_Requisition");
                        Dictionary<string, object> dictionary = new Dictionary<string, object>();
                        dictionary["CodeTime"] = 0;
                        dictionary["UpdateMaxNum"] = 1;
                        List<BillNoInfo> billNo = BusinessDataServiceHelper.GetBillNo(base.Context, formMetaData.BusinessInfo, list.ToArray(), dictionary, "");
                        if (billNo != null && billNo.Count > 0)
                        {
                            for (int i = 0; i < list.Count; i++)
                            {
                                list[i]["BillNo"] = billNo[i].BillNo;
                            }
                        }
                        IOperationResult operationResult = BusinessDataServiceHelper.Draft(base.Context, formMetaData.BusinessInfo, list.ToArray(), null, "");
                        if (operationResult.IsSuccess)
                        {
                            this.SetButtonEnable(false);
                            this.View.ShowMessage("生成采购申请单成功!");
                            return;
                        }
                        this.SetButtonEnable(true);
                        string text = "";
                        foreach (ValidationErrorInfo validationErrorInfo in operationResult.ValidationErrors)
                        {
                            text += validationErrorInfo.Message;
                        }
                        this.View.ShowMessage("生成采购申请单失败!" + text);
                        break;
                    }
            }
        }

        public override void AfterBindData(EventArgs e)
        {
            this.View.StyleManager.SetVisible("FChkSupplyOrgBom", null, false);
            if (this.View.LayoutInfo.GetAppearance("FProgressBar") != null)
            {
                this._progressBar = this.View.GetControl<ProgressBar>("FProgressBar");
                this._progressBar.Visible = false;
            }
            this.View.GetControl("FChkSupplyOrgBom").Visible = this.bChkSupplyOrgBom;
            base.AfterBindData(e);
        }
        public override void OnQueryProgressValue(QueryProgressValueEventArgs e)
        {
            lock (this._lockObject)
            {
                if (this.flag)
                {
                    this.flag = false;
                    e.Value = 100;
                    e.Caption = this._processTips;
                }
                else if (this._processRate >= 100)
                {
                    if (this._progressBar != null)
                    {
                        this._progressBar.Visible = false;
                    }
                    e.Value = 99;
                    this.flag = true;
                }
                else
                {
                    e.Value = this._processRate;
                    e.Caption = this._processTips;
                }
                base.OnQueryProgressValue(e);
            }
        }
        private void GetPriceFromPriceList(List<DynamicObject> lstPurRequisition)
        {
            if (lstPurRequisition != null && lstPurRequisition.Count > 0)
            {
                List<long> list = new List<long>();
                List<long> list2 = new List<long>();
                foreach (DynamicObject dynamicObject in lstPurRequisition)
                {
                    DynamicObjectCollection source = dynamicObject["ReqEntry"] as DynamicObjectCollection;
                    list.AddRange((from q in source
                                   select Convert.ToInt64(q["MaterialId_id"])).Distinct<long>().ToList<long>());
                    list2.AddRange((from q in source
                                    select Convert.ToInt64(q["SuggestSupplierId_id"])).Distinct<long>().ToList<long>());
                }
                list = list.Distinct<long>().ToList<long>();
                list2 = list2.Distinct<long>().ToList<long>();
                Dictionary<long, long> masterIds = PurchaseNewServiceHelper.GetMasterIds(base.Context, "MATERIAL", list);
                Dictionary<long, long> masterIds2 = PurchaseNewServiceHelper.GetMasterIds(base.Context, "SUPPLIER", list2);
                foreach (DynamicObject dynamicObject2 in lstPurRequisition)
                {
                    PurPriceArgsPackage purPriceArgsPackage = this.BuildPurPriceArgsPackage(dynamicObject2, masterIds, masterIds2);
                    List<PurPriceResult> newPurchasePriceForBillConvert = PriceServiceHelper.GetNewPurchasePriceForBillConvert(base.Context, purPriceArgsPackage);
                    decimal num = 0m;
                    if (newPurchasePriceForBillConvert == null || newPurchasePriceForBillConvert.Count == 0)
                    {
                        break;
                    }
                    DynamicObjectCollection dynamicObjectCollection = dynamicObject2["ReqEntry"] as DynamicObjectCollection;
                    for (int i = 0; i < newPurchasePriceForBillConvert.Count; i++)
                    {
                        PurPriceResult purPriceResult = newPurchasePriceForBillConvert[i];
                        int row = purPriceResult.Row;
                        int num2 = row - 1;
                        if (dynamicObjectCollection.Count > num2)
                        {
                            DynamicObject dynamicObject3 = dynamicObjectCollection[num2];
                            dynamicObject3["EvaluatePrice"] = purPriceResult.Price;
                            dynamicObject3["TAXPRICE"] = purPriceResult.TaxPrice;
                            dynamicObject3["TAXRATE"] = purPriceResult.TaxRate;
                            dynamicObject3["UpPrice"] = purPriceResult.UpperPrice;
                            dynamicObject3["DownPrice"] = purPriceResult.LowerPrice;
                            dynamicObject3["PriceListEntry_ID"] = purPriceResult.PriceListId;
                            decimal d = Convert.ToDecimal(dynamicObject3["PriceUnitQty"]);
                            decimal num3 = purPriceResult.Price * d;
                            decimal num4 = purPriceResult.TaxPrice * d;
                            dynamicObject3["Amount"] = num3;
                            dynamicObject3["ReqAmount"] = num4;
                            num += num4;
                        }
                    }
                    dynamicObject2["TotalAmount"] = num;
                }
            }
        }

        private PurPriceArgsPackage BuildPurPriceArgsPackage(DynamicObject billData, Dictionary<long, long> materialMasterIds, Dictionary<long, long> supplierMasterIds)
        {
            PurPriceArgsPackage purPriceArgsPackage = new PurPriceArgsPackage();
            DynamicObjectCollection dynamicObjectCollection = billData["ReqEntry"] as DynamicObjectCollection;
            foreach (DynamicObject dynamicObject in dynamicObjectCollection)
            {
                PurPriceArgs purPriceArgs = new PurPriceArgs();
                purPriceArgs.Row = Convert.ToInt32(dynamicObject["SEQ"]);
                purPriceArgs.CurrentBill = "PUR_Requisition";
                purPriceArgs.PurchaseOrgId = Convert.ToInt64(dynamicObject["PurchaseOrgId_id"]);
                purPriceArgs.CurrencyId = Convert.ToInt64(billData["CurrencyId_Id"]);
                purPriceArgs.MaterialId = Convert.ToInt64(dynamicObject["MaterialId_id"]);
                if (materialMasterIds.ContainsKey(purPriceArgs.MaterialId))
                {
                    purPriceArgs.MaterialMasterId = materialMasterIds[purPriceArgs.MaterialId];
                }
                purPriceArgs.Date = Convert.ToDateTime(dynamicObject["SuggestPurDate"]);
                purPriceArgs.UnitId = Convert.ToInt64(dynamicObject["PriceUnitId_id"]);
                purPriceArgs.Qty = Convert.ToDecimal(dynamicObject["PriceUnitQty"]);
                purPriceArgs.RequireOrgId = Convert.ToInt64(dynamicObject["RequireOrgId_id"]);
                long key = Convert.ToInt64(dynamicObject["SuggestSupplierId_id"]);
                if (supplierMasterIds.ContainsKey(key))
                {
                    purPriceArgs.SupplierMasterId = supplierMasterIds[key];
                }
                purPriceArgs.AuxProp = (dynamicObject["AuxPropId"] as DynamicObject);
                purPriceArgs.AuxPropId = Convert.ToInt64(dynamicObject["AuxPropId_id"]);
                purPriceArgsPackage.PriceArgs.Add(purPriceArgs);
            }
            return purPriceArgsPackage;
        }

        [Obsolete]
        private List<DynamicObject> GenerateReqs(Context ctx, ref bool bHasData)
        {
            List<DynamicObject> list = new List<DynamicObject>();
            if (this._PurRequisitionListMeta == null)
            {
                this._PurRequisitionListMeta = MetaDataServiceHelper.GetFormMetaData(ctx, "PUR_Requisition");
            }
            DynamicObject dynamicObject = new DynamicObject(this._PurRequisitionListMeta.BusinessInfo.GetDynamicObjectType());
            DynamicObjectCollection dynamicObjectCollection = dynamicObject["ReqEntry"] as DynamicObjectCollection;
            ctx.SystemTimeZone.ConvertTime(DateTime.Now.Date, ctx.CurrentUserTimeZone);
            DateTime dateTime = ctx.SystemTimeZone.ConvertTime(DateTime.Now, ctx.CurrentUserTimeZone);
            dynamicObject["DocumentStatus"] = "Z";
            dynamicObject["FFormId"] = "PUR_Requisition";
            dynamicObject["RequestType"] = "Material";
            dynamicObject["ApplicationOrgId_Id"] = this.ReqOrgId;
            JSONObject defCurrencyAndExchangeTypeByBizOrgID = CommonServiceHelper.GetDefCurrencyAndExchangeTypeByBizOrgID(ctx, this.ReqOrgId);
            if (defCurrencyAndExchangeTypeByBizOrgID != null)
            {
                dynamicObject["CurrencyId_Id"] = Convert.ToInt64(defCurrencyAndExchangeTypeByBizOrgID["FCyForID"]);
                dynamicObject["ExchangeTypeId_Id"] = Convert.ToInt64(defCurrencyAndExchangeTypeByBizOrgID["FRateType"]);
            }
            dynamicObject["BillTypeID_Id"] = "93591469feb54ca2b08eb635f8b79de3";
            dynamicObject["ApplicationDate"] = dateTime;
            dynamicObject["CreateDate"] = dateTime;
            dynamicObject["ModifyDate"] = dateTime;
            dynamicObject["CreatorId_Id"] = ctx.UserId;
            dynamicObject["ModifierId_Id"] = ctx.UserId;
            dynamicObject["CloseStatus"] = "A";
            dynamicObject["CancelStatus"] = "A";
            dynamicObject["FISPRICEEXCLUDETAX"] = true;
            DynamicObjectCollection dynamicObjectCollection2 = this.View.Model.DataObject["AssortResult"] as DynamicObjectCollection;
            object[] orgByBizRelationship = OrganizationServiceHelper.GetOrgByBizRelationship(ctx, this.ReqOrgId, 104L, false, true);
            object[] orgByBizRelationship2 = OrganizationServiceHelper.GetOrgByBizRelationship(ctx, this.ReqOrgId, 112L, false, true);
            int num = 1;
            foreach (DynamicObject dynamicObject2 in dynamicObjectCollection2)
            {
                if (Convert.ToBoolean(dynamicObject2["ChkItem"]))
                {
                    decimal num2 = Convert.ToDecimal(dynamicObject2["ReqQty"]);
                    if (!(num2 <= 0m))
                    {
                        DynamicObject dynamicObject3 = dynamicObject2["AssortMaterialID"] as DynamicObject;
                        DynamicObject dynamicObject4 = (dynamicObject3["MaterialBase"] as DynamicObjectCollection)[0];
                        if (Convert.ToBoolean(dynamicObject4["IsPurchase"]) || Convert.ToBoolean(dynamicObject4["IsSubContract"]))
                        {
                            DynamicObject dynamicObject5 = new DynamicObject(dynamicObjectCollection.DynamicCollectionItemPropertyType);
                            dynamicObject5["MaterialId_Id"] = Convert.ToInt64(dynamicObject2["AssortMaterialID_Id"]);
                            long num3 = Convert.ToInt64(dynamicObject2["AssortUnitID_Id"]);
                            dynamicObject5["UnitID_Id"] = num3;
                            dynamicObject5["ReqQty"] = num2;
                            dynamicObject5["ApproveQty"] = num2;
                            dynamicObject5["RemainQty"] = num2;
                            dynamicObject5["Seq"] = num;
                            dynamicObject5["RequireOrgId_Id"] = this.ReqOrgId;
                            dynamicObject5["PurchaseOrgId_Id"] = ((orgByBizRelationship != null && orgByBizRelationship.Length > 0) ? Convert.ToInt64(orgByBizRelationship[0]) : this.ReqOrgId);
                            dynamicObject5["ReceiveOrgId_Id"] = ((orgByBizRelationship2 != null && orgByBizRelationship2.Length > 0) ? Convert.ToInt64(orgByBizRelationship[0]) : this.ReqOrgId);
                            if (dynamicObject3 != null)
                            {
                                dynamicObject5["MaterialDesc"] = Convert.ToString(dynamicObject3["Name"]);
                                long num4 = Convert.ToInt64(dynamicObject4["BaseUnitId_Id"]);
                                dynamicObject5["BaseUnitId_Id"] = num4;
                                DynamicObject dynamicObject6 = (dynamicObject3["MaterialPurchase"] as DynamicObjectCollection)[0];
                                long num5 = Convert.ToInt64(dynamicObject6["PurchasePriceUnitId_Id"]);
                                dynamicObject5["PriceUnitId_Id"] = num5;
                                long materialId = Convert.ToInt64(dynamicObject3["Id"]);
                                decimal num6 = this.UnitConvertQty(ctx, materialId, num3, num2, num4);
                                dynamicObject5["FBaseUnitQty"] = num6;
                                dynamicObject5["BaseReqQty"] = num6;
                                dynamicObject5["PRICEBASEQTY"] = num6;
                                dynamicObject5["ReqStockBaseQty"] = num6;
                                dynamicObject5["SalBaseQty"] = num6;
                                dynamicObject5["PriceUnitQty"] = this.UnitConvertQty(ctx, materialId, num3, num2, num5);
                                DynamicObject dynamicObject7 = (dynamicObject3["MaterialSale"] as DynamicObjectCollection)[0];
                                long num7 = Convert.ToInt64(dynamicObject7["SaleUnitId_Id"]);
                                dynamicObject5["SalUnitID_Id"] = num7;
                                dynamicObject5["SalQty"] = this.UnitConvertQty(ctx, materialId, num3, num2, num7);
                                DynamicObject dynamicObject8 = (dynamicObject3["MaterialStock"] as DynamicObjectCollection)[0];
                                long num8 = Convert.ToInt64(dynamicObject8["StoreUnitID_Id"]);
                                dynamicObject5["ReqStockUnitId_Id"] = num8;
                                dynamicObject5["ReqStockQty"] = this.UnitConvertQty(ctx, materialId, num3, num2, num8);
                                DynamicObject dynamicObject9 = dynamicObject6["DefaultVendor"] as DynamicObject;
                                if (dynamicObject9 != null && Convert.ToInt64(dynamicObject6["PurchaseOrgId_Id"]) == Convert.ToInt64(dynamicObject5["PurchaseOrgId_Id"]))
                                {
                                    long num9 = Convert.ToInt64(dynamicObject9["Id"]);
                                    dynamicObject5["SuggestSupplierId_Id"] = num9;
                                }
                                DynamicObject dynamicObject10 = dynamicObject6["PurchaseGroupId"] as DynamicObject;
                                if (dynamicObject10 != null)
                                {
                                    dynamicObject5["PurchaseGroupId_id"] = Convert.ToInt64(dynamicObject10["Id"]);
                                }
                                DynamicObject dynamicObject11 = dynamicObject6["PurchaserId"] as DynamicObject;
                                if (dynamicObject11 != null)
                                {
                                    dynamicObject5["PurchaserId_id"] = Convert.ToInt64(dynamicObject11["Id"]);
                                }
                            }
                            dynamicObject5["ArrivalDate"] = Convert.ToDateTime(dynamicObject2["AssortDeliveryDate"]);
                            dynamicObject5["SuggestPurDate"] = Convert.ToDateTime(dynamicObject2["AssortDeliveryDate"]);
                            dynamicObject5["PlanConfirm"] = true;
                            dynamicObject5["MRPTerminateStatus"] = 'A';
                            dynamicObject5["MRPCloseStatus"] = 'A';
                            dynamicObject5["HasPublish"] = 'A';
                            dynamicObject5["RowPublishStatus"] = '0';
                            dynamicObject5["AuxpropId_Id"] = Convert.ToInt64(dynamicObject2["AuxpropId_Id"]);
                            dynamicObjectCollection.Add(dynamicObject5);
                            num++;
                        }
                    }
                }
            }
            if (dynamicObjectCollection.Count > 0)
            {
                bHasData = true;
            }
            list.Add(dynamicObject);
            return list;
        }

        [Obsolete]
        private decimal UnitConvertQty(Context ctx, long materialId, long sourceUnitId, decimal sourceUnitQty, long destUnitId)
        {
            if (sourceUnitQty == 0m)
            {
                return 0m;
            }
            if (sourceUnitId == destUnitId)
            {
                return sourceUnitQty;
            }
            UnitConvert unitConvertRate = UnitConvertServiceHelper.GetUnitConvertRate(ctx, new GetUnitConvertRateArgs
            {
                MaterialId = materialId,
                SourceUnitId = sourceUnitId,
                DestUnitId = destUnitId
            });
            return unitConvertRate.ConvertQty(sourceUnitQty, "");
        }

        [Obsolete]
        private void ShowAssortResult()
        {
            if (this.isCalculated)
            {
                return;
            }

            this.isCalculated = true;
            this._processRate = 0;
            this._processTips = ResManager.LoadKDString("正在计算，当前进度（0%）", "004015030006330", SubSystemType.SCM, new object[0]);
            if (this._progressBar != null)
            {
                this._progressBar.Start(1);
                this._progressBar.SetValue(0);
                this._progressBar.Visible = true;
            }
            this.SetButtonEnable(false);
            MainWorker.QuequeTask(base.Context, delegate ()
            {
                CultureInfoUtils.SetCurrentLanguage(base.Context);
                this.AssortCalculation();
            }, delegate (AsynResult result)
            {
                CultureInfoUtils.SetCurrentLanguage(base.Context);
                this.isCalculated = false;
                this.SetButtonEnable(true);
            });
        }

        [Obsolete]
        private void AssortCalculation()
        {
            try
            {
                this.ChangeProcess(10m);
                MemBomExpandOption memBomExpandOption = this.BuildBomExpandOption();
                this.ChangeProcess(20m);
                DynamicObject bomExpandResult = this.GetBomExpandResult(memBomExpandOption);
                this.ChangeProcess(30m);
                List<BomDataNode> nodes = this.ConvertBomExpandResultToNodes(bomExpandResult);
                this.ChangeProcess(40m);
                this.ConvertNodeListToNodeTree(nodes);
                this.ChangeProcess(60m);
                List<BomDataNode> nodes2 = this.FiltNodes(nodes);
                this.ChangeProcess(70m);
                List<BomDataNode> nodes3 = this.CalculateNodeQty(nodes2);
                this.ChangeProcess(80m);
                List<BomDataNode> nodes4 = this.MergeNodes(nodes3);
                List<BomDataNode> finalLeafNodes = this.CalculateReqQty(nodes4);
                this.ChangeProcess(90m);
                this.UpdateResultEntity(finalLeafNodes);
                this.ChangeProcess(95m);
                MFGServiceHelperForSCM.ClearBomExpandResult(base.Context, memBomExpandOption);
                this.ChangeProcess(100m);
            }
            catch (Exception ex)
            {
                this.ChangeProcess(100m);
                Logger.Error("SCM", "", ex);

                this.View.ShowErrMessage(string.Format("计算过程中发生错误:{0}", ex.Message));
            }
        }

        private void UpdateResultEntity(List<BomDataNode> finalLeafNodes)
        {
            if (this.View.Model.GetEntryRowCount("FAssortResult") > 0)
            {
                this.View.Model.DeleteEntryData("FAssortResult");
            }
            if (finalLeafNodes == null || finalLeafNodes.Count <= 0)
            {
                this.View.UpdateView("FAssortResult");
                return;
            }
            bool flag = Convert.ToBoolean(this.View.Model.GetValue("FIsZeroQty"));
            int num = 0;
            Entity entity = this.View.BusinessInfo.GetEntity("FAssortResult");
            for (int i = 0; i < finalLeafNodes.Count; i++)
            {
                BomDataNode bomDataNode = finalLeafNodes[i];
                if (!flag || !(bomDataNode.ReqQty <= 0m))
                {
                    this.View.Model.CreateNewEntryRow(entity, num);
                    this.View.Model.SetValue("FAssortMaterialID", bomDataNode.CMaterialId_Id, num);
                    this.View.Model.SetValue("FAssortUnitID", bomDataNode.PurchaseUnitId, num);
                    this.View.Model.SetValue("FMaterialBaseUnitID", bomDataNode.BaseUnitId, num);
                    this.View.Model.SetValue("FGrossQty", bomDataNode.GrossQty, num);
                    this.View.Model.SetValue("FHandInventory", bomDataNode.UsefulStockQty, num);
                    this.View.Model.SetValue("FSafeStock", bomDataNode.SafeStockQty, num);
                    this.View.Model.SetValue("FReqQty", bomDataNode.ReqQty, num);
                    this.View.Model.SetValue("FAssortDeliveryDate", bomDataNode.NeedDate, num);
                    this.View.Model.SetValue("FAuxpropId", bomDataNode.AuxPropId_Id, num);
                    this.View.Model.SetValue("FFixScrapQty", bomDataNode.FixScrapQty, num);
                    this.View.Model.SetValue("FScrapRate", bomDataNode.ScrapRate, num);
                    this.View.Model.SetValue("FScrapQty", bomDataNode.ScrapQty, num);
                    num++;
                }
            }
            this.View.UpdateView("FAssortResult");
        }

        private List<BomDataNode> CalculateReqQty(List<BomDataNode> nodes)
        {
            if (nodes == null || nodes.Count <= 0)
            {
                return new List<BomDataNode>();
            }
            if (this.IsSpoilage && this.IsSafeStock)
            {
                using (List<BomDataNode>.Enumerator enumerator = nodes.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        BomDataNode bomDataNode = enumerator.Current;
                        bomDataNode.ReqQty = MathUtil.Round(bomDataNode.GrossQty * +(bomDataNode.ScrapRate / 100m) + bomDataNode.FixScrapQty + bomDataNode.SafeStockQty - bomDataNode.UsefulStockQty, bomDataNode.PurchaseUnitDecimal, (RoundMode)2);
                    }
                    return nodes;
                }
            }
            if (!this.IsSpoilage && this.IsSafeStock)
            {
                foreach (BomDataNode bomDataNode2 in nodes)
                {
                    bomDataNode2.ReqQty = MathUtil.Round(bomDataNode2.GrossQty + bomDataNode2.SafeStockQty - bomDataNode2.UsefulStockQty, bomDataNode2.PurchaseUnitDecimal, (RoundMode)2);
                }
            }
            return nodes;
        }

        private List<BomDataNode> MergeNodes(List<BomDataNode> nodes)
        {
            if (nodes == null || nodes.Count <= 0)
            {
                return null;
            }
            List<BomDataNode> list = new List<BomDataNode>();
            if (this.IsAuxProp)
            {
                var enumerable = from p in nodes
                                 group p by new
                                 {
                                     p.CMaterialId_Id,
                                     p.AuxPropId_Id,
                                     p.ScrapRate,
                                     p.BaseFixScrapQty
                                 };
                using (var enumerator = enumerable.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        var grouping = enumerator.Current;
                        BomDataNode bomDataNode = grouping.FirstOrDefault<BomDataNode>();
                        List<BomDataNode> list2 = list;
                        BomDataNode bomDataNode2 = new BomDataNode();
                        bomDataNode2.CMaterialId_Id = grouping.Key.CMaterialId_Id;
                        bomDataNode2.AuxPropId_Id = grouping.Key.AuxPropId_Id;
                        bomDataNode2.ScrapRate = grouping.Key.ScrapRate;
                        bomDataNode2.BaseFixScrapQty = grouping.Key.BaseFixScrapQty;
                        bomDataNode2.MaterialMasterId = bomDataNode.MaterialMasterId;
                        bomDataNode2.BaseUnitId = bomDataNode.BaseUnitId;
                        bomDataNode2.PurchaseUnitId = bomDataNode.PurchaseUnitId;
                        bomDataNode2.StockUnitId = bomDataNode.StockUnitId;
                        bomDataNode2.ErpClsID = bomDataNode.ErpClsID;
                        bomDataNode2.PurURNum = bomDataNode.PurURNum;
                        bomDataNode2.PurURNom = bomDataNode.PurURNom;
                        bomDataNode2.IsPurchase = bomDataNode.IsPurchase;
                        bomDataNode2.SafeStockQty = bomDataNode.SafeStockQty;
                        bomDataNode2.UsefulStockQty = bomDataNode.UsefulStockQty;
                        bomDataNode2.Denominator = bomDataNode.Denominator;
                        bomDataNode2.Numerator = bomDataNode.Numerator;
                        bomDataNode2.MatName = bomDataNode.MatName;
                        bomDataNode2.MatNumber = bomDataNode.MatNumber;
                        bomDataNode2.OMaterialId_Id = bomDataNode.OMaterialId_Id;
                        bomDataNode2.PurchaseUnitDecimal = bomDataNode.PurchaseUnitDecimal;
                        bomDataNode2.BaseQty = grouping.Sum((BomDataNode p) => p.BaseQty);
                        bomDataNode2.BaseActualQty = grouping.Sum((BomDataNode p) => p.BaseActualQty);
                        bomDataNode2.ScrapQty = grouping.Sum((BomDataNode p) => p.ScrapQty);
                        bomDataNode2.ReqQty = grouping.Sum((BomDataNode p) => p.ReqQty);
                        bomDataNode2.GrossQty = grouping.Sum((BomDataNode p) => p.GrossQty);
                        bomDataNode2.NeedDate = grouping.Min((BomDataNode P) => P.NeedDate);
                        list2.Add(bomDataNode2);
                    }
                    return list;
                }
            }
            var enumerable2 = from p in nodes
                              group p by new
                              {
                                  p.CMaterialId_Id,
                                  p.ScrapRate,
                                  p.BaseFixScrapQty
                              };
            foreach (var grouping2 in enumerable2)
            {
                BomDataNode bomDataNode3 = grouping2.FirstOrDefault<BomDataNode>();
                List<BomDataNode> list3 = list;
                BomDataNode bomDataNode4 = new BomDataNode();
                bomDataNode4.CMaterialId_Id = grouping2.Key.CMaterialId_Id;
                bomDataNode4.ScrapRate = grouping2.Key.ScrapRate;
                bomDataNode4.BaseFixScrapQty = grouping2.Key.BaseFixScrapQty;
                bomDataNode4.AuxPropId_Id = 0L;
                bomDataNode4.MaterialMasterId = bomDataNode3.MaterialMasterId;
                bomDataNode4.BaseUnitId = bomDataNode3.BaseUnitId;
                bomDataNode4.PurchaseUnitId = bomDataNode3.PurchaseUnitId;
                bomDataNode4.StockUnitId = bomDataNode3.StockUnitId;
                bomDataNode4.ErpClsID = bomDataNode3.ErpClsID;
                bomDataNode4.PurURNum = bomDataNode3.PurURNum;
                bomDataNode4.PurURNom = bomDataNode3.PurURNom;
                bomDataNode4.IsPurchase = bomDataNode3.IsPurchase;
                bomDataNode4.SafeStockQty = bomDataNode3.SafeStockQty;
                bomDataNode4.UsefulStockQty = bomDataNode3.UsefulStockQty;
                bomDataNode4.Denominator = bomDataNode3.Denominator;
                bomDataNode4.Numerator = bomDataNode3.Numerator;
                bomDataNode4.MatName = bomDataNode3.MatName;
                bomDataNode4.MatNumber = bomDataNode3.MatNumber;
                bomDataNode4.OMaterialId_Id = bomDataNode3.OMaterialId_Id;
                bomDataNode4.PurchaseUnitDecimal = bomDataNode3.PurchaseUnitDecimal;
                bomDataNode4.BaseQty = grouping2.Sum((BomDataNode p) => p.BaseQty);
                bomDataNode4.BaseActualQty = grouping2.Sum((BomDataNode p) => p.BaseActualQty);
                bomDataNode4.ScrapQty = grouping2.Sum((BomDataNode p) => p.ScrapQty);
                bomDataNode4.ReqQty = grouping2.Sum((BomDataNode p) => p.ReqQty);
                bomDataNode4.GrossQty = grouping2.Sum((BomDataNode p) => p.GrossQty);
                bomDataNode4.NeedDate = grouping2.Min((BomDataNode P) => P.NeedDate);
                list3.Add(bomDataNode4);
            }
            return list;
        }

        [Obsolete]
        private List<BomDataNode> CalculateNodeQty(List<BomDataNode> nodes)
        {
            if (nodes == null || nodes.Count <= 0)
            {
                return new List<BomDataNode>();
            }
            string empty = string.Empty;
            Dictionary<string, int> invStockKeyRowMaps = new Dictionary<string, int>();
            List<GetInvStockResult> invStockResults = this.GetInvStockResults(nodes, out invStockKeyRowMaps);
            Dictionary<int, decimal> dictionary = new Dictionary<int, decimal>();
            foreach (GetInvStockResult getInvStockResult in invStockResults)
            {
                if (!dictionary.ContainsKey(getInvStockResult.Row))
                {
                    dictionary.Add(getInvStockResult.Row, getInvStockResult.StockQty);
                }
            }
            List<long> list = (from p in nodes
                               select p.CMaterialId_Id).Distinct<long>().ToList<long>();
            Dictionary<long, decimal> safeStock = PurchaseServiceHelper.GetSafeStock(this.View.Context, list, this.ReqOrgId);
            if (!this.IsSpoilage && !this.IsSafeStock)
            {
                using (List<BomDataNode>.Enumerator enumerator2 = nodes.GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        BomDataNode bomDataNode = enumerator2.Current;
                        this.SetNodeStockQty(dictionary, invStockKeyRowMaps, safeStock, bomDataNode);
                        bomDataNode.GrossQty = MathUtil.Round(bomDataNode.Qty, bomDataNode.PurchaseUnitDecimal, (RoundMode)2);
                        bomDataNode.ReqQty = MathUtil.Round(bomDataNode.Qty, bomDataNode.PurchaseUnitDecimal, (RoundMode)2);
                    }
                    return nodes;
                }
            }
            if (this.IsSpoilage && !this.IsSafeStock)
            {
                using (List<BomDataNode>.Enumerator enumerator3 = nodes.GetEnumerator())
                {
                    while (enumerator3.MoveNext())
                    {
                        BomDataNode bomDataNode2 = enumerator3.Current;
                        this.SetNodeStockQty(dictionary, invStockKeyRowMaps, safeStock, bomDataNode2);
                        bomDataNode2.GrossQty = MathUtil.Round(bomDataNode2.ParentActualQty * bomDataNode2.Numerator / bomDataNode2.Denominator, bomDataNode2.PurchaseUnitDecimal, (RoundMode)2);
                        bomDataNode2.ReqQty = MathUtil.Round(bomDataNode2.GrossQty * +(bomDataNode2.ScrapRate / 100m) + bomDataNode2.FixScrapQty, bomDataNode2.PurchaseUnitDecimal, (RoundMode)2);
                        bomDataNode2.ScrapQty = MathUtil.Round(bomDataNode2.GrossQty * bomDataNode2.ScrapRate / 100m + bomDataNode2.FixScrapQty, bomDataNode2.PurchaseUnitDecimal, (RoundMode)2);
                    }
                    return nodes;
                }
            }
            if (this.IsSpoilage && this.IsSafeStock)
            {
                using (List<BomDataNode>.Enumerator enumerator4 = nodes.GetEnumerator())
                {
                    while (enumerator4.MoveNext())
                    {
                        BomDataNode bomDataNode3 = enumerator4.Current;
                        this.SetNodeStockQty(dictionary, invStockKeyRowMaps, safeStock, bomDataNode3);
                        bomDataNode3.GrossQty = MathUtil.Round(bomDataNode3.ParentActualQty * bomDataNode3.Numerator / bomDataNode3.Denominator, bomDataNode3.PurchaseUnitDecimal, (RoundMode)2);
                        bomDataNode3.ScrapQty = MathUtil.Round(bomDataNode3.GrossQty * bomDataNode3.ScrapRate / 100m + bomDataNode3.FixScrapQty, bomDataNode3.PurchaseUnitDecimal, (RoundMode)2);
                    }
                    return nodes;
                }
            }
            if (!this.IsSpoilage && this.IsSafeStock)
            {
                foreach (BomDataNode bomDataNode4 in nodes)
                {
                    this.SetNodeStockQty(dictionary, invStockKeyRowMaps, safeStock, bomDataNode4);
                    bomDataNode4.GrossQty = MathUtil.Round(bomDataNode4.Qty, bomDataNode4.PurchaseUnitDecimal, (RoundMode)2);
                }
            }
            return nodes;
        }

        [Obsolete]
        private void SetNodeStockQty(Dictionary<int, decimal> invStockResultsDic, Dictionary<string, int> invStockKeyRowMaps, Dictionary<long, decimal> safeStockQtyDataDic, BomDataNode item)
        {
            decimal num = 0m;
            if (safeStockQtyDataDic.TryGetValue(item.CMaterialId_Id, out num))
            {
                item.SafeStockQty = this.UnitConvertQty(base.Context, item.CMaterialId_Id, item.StockUnitId, num, item.PurchaseUnitId);
            }
            num = 0m;
            string key = string.Empty;
            if (this.IsAuxProp)
            {
                key = item.CMaterialId_Id + item.AuxPropId_Id + string.Empty;
            }
            else
            {
                key = item.CMaterialId_Id + string.Empty;
            }
            int key2 = 0;
            if (invStockKeyRowMaps.TryGetValue(key, out key2) && invStockResultsDic.TryGetValue(key2, out num))
            {
                item.UsefulStockQty = num;
            }
        }

        private List<GetInvStockResult> GetInvStockResults(List<BomDataNode> nodes, out Dictionary<string, int> invStockKeyRowMaps)
        {
            invStockKeyRowMaps = new Dictionary<string, int>();
            GetInvStockArgs getInvStockArgs = new GetInvStockArgs();
            getInvStockArgs.service = new GetInvStockBusinessServiceMeta
            {
                ReturnQtyField = "2",
                PreCondition = Convert.ToString(this.isAllowMRP),
                PluginClassName = "Kingdee.K3.SCM.App.Core.PurAssortReqGetInvStock,Kingdee.K3.SCM.App.Core"
            };
            int value = 0;
            foreach (BomDataNode bomDataNode in nodes)
            {
                string key = string.Empty;
                if (this.IsAuxProp)
                {
                    key = bomDataNode.CMaterialId_Id + bomDataNode.AuxPropId_Id + string.Empty;
                }
                else
                {
                    key = bomDataNode.CMaterialId_Id + string.Empty;
                }
                if (!invStockKeyRowMaps.ContainsKey(key))
                {
                    invStockKeyRowMaps.Add(key, value);
                    GetInvStockDetailArg getInvStockDetailArg = new GetInvStockDetailArg();
                    getInvStockDetailArg.Row = value++;
                    getInvStockDetailArg.StockOrgId = this.ReqOrgId;
                    getInvStockDetailArg.MaterialId = bomDataNode.CMaterialId_Id;
                    getInvStockDetailArg.MaterialMasterId = bomDataNode.MaterialMasterId;
                    getInvStockDetailArg.UnitId = bomDataNode.PurchaseUnitId;
                    getInvStockDetailArg.BaseUnitId = bomDataNode.BaseUnitId;
                    getInvStockDetailArg.AuxPropId = bomDataNode.AuxPropId_Id;
                    getInvStockArgs.StockDetailArg.Add(getInvStockDetailArg);
                }
            }
            return Kingdee.K3.SCM.ServiceHelper.StockServiceHelper.GetInvStock(this.View.Context, getInvStockArgs);
        }

        private List<BomDataNode> FiltNodes(List<BomDataNode> nodes)
        {
            if (nodes == null || nodes.Count <= 0)
            {
                return new List<BomDataNode>();
            }
            nodes.RemoveAll((BomDataNode p) => !p.HasSetRelation);
            if (nodes == null || nodes.Count <= 0)
            {
                return new List<BomDataNode>();
            }
            List<BomDataNode> list = (from p in nodes
                                      where p.IsFinalNode && p.IsPurchase
                                      select p).ToList<BomDataNode>();
            if (list == null || list.Count <= 0)
            {
                return new List<BomDataNode>();
            }
            bool flag = Convert.ToBoolean(this.View.Model.GetValue("FIsSumZZ"));
            bool flag2 = Convert.ToBoolean(this.View.Model.GetValue("FIsSumSub"));
            bool flag3 = Convert.ToBoolean(this.View.Model.GetValue("FIsSumPur"));
            if (!Convert.ToBoolean(this.View.Model.GetValue("FIsSumAll")))
            {
                if (!flag)
                {
                    list.RemoveAll((BomDataNode p) => p.ErpClsID == "2");
                }
                if (!flag2)
                {
                    list.RemoveAll((BomDataNode p) => p.ErpClsID == "3");
                }
                if (!flag3)
                {
                    list.RemoveAll((BomDataNode p) => p.ErpClsID == "1");
                }
            }
            return list;
        }

        private void ConvertNodeListToNodeTree(List<BomDataNode> nodes)
        {
            if (nodes == null || nodes.Count <= 0)
            {
                return;
            }
            IEnumerable<IGrouping<int, BomDataNode>> enumerable = from p in nodes
                                                                  group p by p.SrcSeqNo;
            foreach (IGrouping<int, BomDataNode> grouping in enumerable)
            {
                BomDataNode parentNode = grouping.FirstOrDefault((BomDataNode p) => p.IsRootNode);
                this.SetGroupNodeRelation(grouping, parentNode);
            }
        }

        private void SetGroupNodeRelation(IGrouping<int, BomDataNode> groupNodes, BomDataNode parentNode)
        {
            parentNode.HasSetRelation = true;
            if (parentNode.ErpClsID == "1")
            {
                return;
            }
            IEnumerable<BomDataNode> enumerable = from p in groupNodes
                                                  where p.ParentNodeId == parentNode.Id
                                                  select p;
            if (enumerable != null)
            {
                foreach (BomDataNode bomDataNode in enumerable)
                {
                    bomDataNode.ParentNode = parentNode;
                    parentNode.ChindrenNodes.Add(bomDataNode);
                    this.SetGroupNodeRelation(groupNodes, bomDataNode);
                }
            }
        }

        private List<BomDataNode> ConvertBomExpandResultToNodes(DynamicObject bomExpandDataObject)
        {
            List<BomDataNode> list = new List<BomDataNode>();
            if (bomExpandDataObject == null)
            {
                return list;
            }
            DynamicObjectCollection dynamicObjectCollection = bomExpandDataObject["BomExpandResult"] as DynamicObjectCollection;
            if (dynamicObjectCollection == null || dynamicObjectCollection.Count <= 0)
            {
                return list;
            }
            foreach (DynamicObject dynamicObject in dynamicObjectCollection)
            {
                BomDataNode bomDataNode = new BomDataNode();
                bomDataNode.AuxPropId_Id = Convert.ToInt64(dynamicObject["AuxPropId_Id"]);
                bomDataNode.OMaterialId_Id = Convert.ToInt64(dynamicObject["MATERIALID_Id"]);
                bomDataNode.BaseUnitId = Convert.ToInt64(dynamicObject["BaseUnitId_Id"]);
                bomDataNode.ParentNodeId = Convert.ToString(dynamicObject["ParentEntryId"]);
                bomDataNode.Id = Convert.ToString(dynamicObject["RowId"]);
                DynamicObject dynamicObject2 = dynamicObject["MaterialId"] as DynamicObject;
                bomDataNode.MaterialMasterId = Convert.ToInt64(dynamicObject2["msterId"]);
                bomDataNode.MatName = Convert.ToString(dynamicObject2["number"]);
                bomDataNode.MatName = Convert.ToString(dynamicObject2["name"]);
                bomDataNode.NeedDate = Convert.ToDateTime(dynamicObject["NeedDate"]);
                bomDataNode.SrcSeqNo = Convert.ToInt32(dynamicObject["SrcSeqNo"]);
                bomDataNode.BaseQty = Convert.ToDecimal(dynamicObject["BaseQty"]);
                bomDataNode.BaseActualQty = Convert.ToDecimal(dynamicObject["BaseActualQty"]);
                if (this.IsSpoilage)
                {
                    bomDataNode.ScrapRate = Convert.ToDecimal(dynamicObject["ScrapRate"]);
                    bomDataNode.BaseFixScrapQty = Convert.ToDecimal(dynamicObject["BaseFixScrapQty"]);
                }
                bomDataNode.Numerator = Convert.ToDecimal(dynamicObject["Numerator"]);
                bomDataNode.Denominator = Convert.ToDecimal(dynamicObject["Denominator"]);
                list.Add(bomDataNode);
            }
            if (list.Count > 0)
            {
                string text = "select t.fmaterialid as fcmaterialid,t.fmasterid,tmb.ferpclsid,tmb.FISPURCHASE ,tt.FSTOREUNITID,tp.FPURCHASEUNITID,tp.FPurURNum,tp.FPurURNom,tu.FPRECISION   from t_bd_material t   INNER JOIN TABLE(fn_StrSplit(@FID, ',', 1)) b ON t.fmasterid = b.FID    inner join t_bd_materialbase tmb on tmb.fmaterialid=t.fmaterialid     inner join t_bd_materialstock tt on tt.fmaterialid=t.fmaterialid     inner join t_bd_materialpurchase tp on tp.fmaterialid=t.fmaterialid    left join t_bd_unit tu on tu.funitid=tp.FPURCHASEUNITID     where t.fuseorgid=@useorgid ; ";


                List<SqlParam> list2 = new List<SqlParam>();
                list2.Add(new SqlParam("@FID", (KDDbType)161, (from p in list
                                                               select p.MaterialMasterId).Distinct<long>().ToArray<long>()));
                list2.Add(new SqlParam("@useorgid", (KDDbType)12, this.ReqOrgId));
                List<BomDbUpdateData> list3 = new List<BomDbUpdateData>();
                using (IDataReader dataReader = DBServiceHelper.ExecuteReader(base.Context, text, list2))
                {
                    while (dataReader.Read())
                    {
                        list3.Add(new BomDbUpdateData
                        {
                            CMaterialId_Id = Convert.ToInt64(dataReader["fcmaterialid"]),
                            MaterialMasterId = Convert.ToInt64(dataReader["fmasterid"]),
                            ErpClsID = Convert.ToString(dataReader["ferpclsid"]),
                            StockUnitId = Convert.ToInt64(dataReader["FSTOREUNITID"]),
                            PurchaseUnitId = Convert.ToInt64(dataReader["FPURCHASEUNITID"]),
                            PurURNom = Convert.ToInt64(dataReader["FPurURNom"]),
                            PurURNum = Convert.ToInt64(dataReader["FPurURNum"]),
                            IsPurchase = (Convert.ToString(dataReader["FISPURCHASE"]) == "1"),
                            PurchaseUnitDecimal = Convert.ToInt32(dataReader["FPRECISION"])
                        });
                    }
                }
                using (List<BomDbUpdateData>.Enumerator enumerator2 = list3.GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        BomDbUpdateData item = enumerator2.Current;
                        List<BomDataNode> list4 = (from p in list
                                                   where p.MaterialMasterId == item.MaterialMasterId
                                                   select p).ToList<BomDataNode>();
                        if (list4 != null)
                        {
                            foreach (BomDataNode bomDataNode2 in list4)
                            {
                                bomDataNode2.ErpClsID = item.ErpClsID;
                                bomDataNode2.CMaterialId_Id = item.CMaterialId_Id;
                                bomDataNode2.StockUnitId = item.StockUnitId;
                                bomDataNode2.PurchaseUnitId = item.PurchaseUnitId;
                                bomDataNode2.PurURNom = item.PurURNom;
                                bomDataNode2.PurURNum = item.PurURNum;
                                bomDataNode2.IsPurchase = item.IsPurchase;
                                bomDataNode2.PurchaseUnitDecimal = item.PurchaseUnitDecimal;
                            }
                        }
                    }
                }
            }
            return list;
        }

        private DynamicObject GetBomExpandResult(MemBomExpandOption bomExpandOption)
        {
            DynamicObjectCollection dynamicObjectCollection = this.View.Model.DataObject["SummaryData"] as DynamicObjectCollection;
            List<DynamicObject> list = new List<DynamicObject>();
            foreach (DynamicObject dynamicObject in dynamicObjectCollection)
            {
                long bomId_Id;
                if (!Convert.ToBoolean(dynamicObject["ChkSupplyOrgBom"]))
                {
                    if (dynamicObject["BomId"] == null || dynamicObject["MaterialId"] == null)
                    {
                        continue;
                    }
                    bomId_Id = Convert.ToInt64(dynamicObject["BomId_Id"]);
                }
                else
                {
                    if (dynamicObject["SupplyOrgBomId"] == null || dynamicObject["MaterialId"] == null)
                    {
                        continue;
                    }
                    bomId_Id = Convert.ToInt64(dynamicObject["SupplyOrgBomId_Id"]);
                }
                int num = Convert.ToInt32(dynamicObject["Seq"]);
                long materialId_Id = Convert.ToInt64(dynamicObject["MaterialId_Id"]);
                long unitId_Id = Convert.ToInt64(dynamicObject["UnitId_Id"]);
                long baseUnitId_Id = Convert.ToInt64(dynamicObject["BaseUnitId_Id"]);
                long auxPropId = Convert.ToInt64(dynamicObject["HeadAuxpropId_Id"]);
                decimal num2 = Convert.ToDecimal(dynamicObject["BaseQty"]);
                if (!(0m >= num2))
                {
                    BomForwardSourceDynamicRow bomForwardSourceDynamicRow = BomForwardSourceDynamicRow.CreateInstance();
                    bomForwardSourceDynamicRow.MaterialId_Id = materialId_Id;
                    bomForwardSourceDynamicRow.BomId_Id = bomId_Id;
                    bomForwardSourceDynamicRow.NeedQty = num2;
                    bomForwardSourceDynamicRow.NeedDate = new DateTime?(Convert.ToDateTime(dynamicObject["DeliveryDate"]));
                    bomForwardSourceDynamicRow.TimeUnit = 1.ToString();
                    bomForwardSourceDynamicRow.UnitId_Id = unitId_Id;
                    bomForwardSourceDynamicRow.BaseUnitId_Id = baseUnitId_Id;
                    bomForwardSourceDynamicRow.SrcInterId = 0L;
                    bomForwardSourceDynamicRow.SrcEntryId = 0L;
                    bomForwardSourceDynamicRow.SrcSeqNo = (long)num;
                    bomForwardSourceDynamicRow.AuxPropId = auxPropId;
                    list.Add(bomForwardSourceDynamicRow.DataEntity);
                }
            }
            if (list == null || list.Count<DynamicObject>() < 1)
            {
                return null;
            }
            return MFGServiceHelperForSCM.ExpandBomForward(base.Context, list, bomExpandOption);
        }

        private MemBomExpandOption BuildBomExpandOption()
        {
            Kingdee.K3.Core.MFG.EnumConst.Enums.Enu_BomExpandCalType enu_BomExpandCalType = 0;
            if (this.orgBomExpandCalTypeDics.ContainsKey(this.ReqOrgId))
            {
                enu_BomExpandCalType = this.orgBomExpandCalTypeDics[this.ReqOrgId];
            }
            else
            {
                string s = Convert.ToString(CommonServiceHelper.GetSystemProfile(base.Context, this.ReqOrgId, "MFG_EngParameter", "ForwardRG", 1));
                int num = 0;
                if (int.TryParse(s, out num))
                {
                    enu_BomExpandCalType = (Kingdee.K3.Core.MFG.EnumConst.Enums.Enu_BomExpandCalType)((num == 1) ? 1 : 2);
                }
                this.orgBomExpandCalTypeDics.Add(this.ReqOrgId, enu_BomExpandCalType);
            }
            return new MemBomExpandOption
            {
                BomExpandCalType = enu_BomExpandCalType,
                DeleteVirtualMaterial = false,
                DeleteSkipRow = false,
                ExpandLevelTo = 30,
                ValidDate = new DateTime?(TimeServiceHelper.GetSystemDateTime(base.Context).Date),
                IsConvertUnitQty = true,
                BomExpandId = SequentialGuid.NewGuid().ToString()
            };
        }

        private void ChangeProcess(decimal rate)
        {
            this._processRate += (int)Math.Round(rate);
            this._processTips = string.Format(ResManager.LoadKDString("当前完成（{0}%）", "004015000017481", (SubSystemType)5, new object[0]), (this._processRate > 100) ? 100 : this._processRate);
        }

        private void SetButtonEnable(bool isCanUse)
        {
            this.View.GetMainBarItem("tbDraw").Enabled = isCanUse;
            this.View.GetMainBarItem("tbAssortReq").Enabled = isCanUse;
            this.View.GetMainBarItem("tbGenerateReqs").Enabled = isCanUse;
        }

        private void GetBOMInfo()
        {
            ListSelBillShowParameter listSelBillShowParameter = new ListSelBillShowParameter();
            listSelBillShowParameter.FormId = "ENG_BOM";
            listSelBillShowParameter.ParentPageId = this.View.PageId;
            listSelBillShowParameter.ListFilterParameter.Filter = string.Format(" FDOCUMENTSTATUS = 'C' AND FFORBIDSTATUS = 'A' and exists (select 1 from t_BD_Material tbm where fmaterialid=tbm.fmaterialid and tbm.FDOCUMENTSTATUS='C' and tbm.FFORBIDSTATUS='A') ", new object[0]);
            listSelBillShowParameter.ListFilterParameter.SelectEntitys = new List<string>
            {
                "ENG_BOM"
            };
            listSelBillShowParameter.CustomParams.Add("AssortReq", "1");
            listSelBillShowParameter.IsLookUp = true;
            listSelBillShowParameter.IsShowFilter = false;
            listSelBillShowParameter.IsShowApproved = true;
            listSelBillShowParameter.IsShowUsed = true;
            List<long> permissionOrg = PermissionServiceHelper.GetPermissionOrg(base.Context, new BusinessObject
            {
                Id = "ENG_BOM"
            }, "6e44119a58cb4a8e86f6c385e14a17ad");
            permissionOrg.Add(0L);
            listSelBillShowParameter.MutilListUseOrgId = string.Join<long>(",", permissionOrg);
            listSelBillShowParameter.IsIsolationOrg = true;
            List<long> lstIds = null;
            if (this.View.Session != null && this.View.Session.ContainsKey("ReturnInsertData"))
            {
                this.View.Session.Remove("ReturnInsertData");
            }
            this.View.ShowForm(listSelBillShowParameter, delegate (FormResult reusult)
            {
                this.listSelects = (reusult.ReturnData as ListSelectedRowCollection);
                if (this.listSelects != null && this.listSelects.Count > 0)
                {
                    lstIds = (from p in this.listSelects
                              select Convert.ToInt64(p.PrimaryKeyValue)).ToList<long>();
                    this.ShowBOMData(lstIds);
                }
            });
        }

        private void ShowBOMData(List<long> lstIds)
        {
            if (lstIds.Count <= 0)
            {
                return;
            }
            DynamicObjectCollection bomsummaryData = PurchaseServiceHelper.GetBOMSummaryData(base.Context, lstIds);
            if ((this.View.Session == null || !this.View.Session.ContainsKey("ReturnInsertData")) && this.View.Model.GetEntryRowCount("FSummaryData") != 0)
            {
                this.View.Model.DeleteEntryData("FSummaryData");
            }
            int num = 0;
            foreach (DynamicObject dynamicObject in bomsummaryData)
            {
                Entity entity = this.View.BusinessInfo.GetEntity("FSummaryData");
                this.View.Model.CreateNewEntryRow(entity, num);
                this.View.Model.SetValue("FMaterialId", Convert.ToInt64(dynamicObject["FMATERIALID"]), num);
                this.View.Model.SetValue("FUnitId", Convert.ToInt64(dynamicObject["FUNITID"]), num);
                this.View.Model.SetValue("FBomId", Convert.ToInt64(dynamicObject["FID"]), num);
                this.View.Model.SetValue("FBaseUnitId", Convert.ToInt64(dynamicObject["FBASEUNITID"]), num);
                this.View.Model.SetValue("FHeadAuxpropId", Convert.ToInt64(dynamicObject["FAUXPROPID"]), num);
                num++;
            }
            this.View.UpdateView();
        }

        [Obsolete]
        private void GetOutsourcingInfo()
        {
            ListSelBillShowParameter listSelBillShowParameter = new ListSelBillShowParameter();
            listSelBillShowParameter.FormId = "SUB_SUBREQORDER";
            listSelBillShowParameter.ParentPageId = this.View.PageId;
            listSelBillShowParameter.ListFilterParameter.Filter = string.Format("FDOCUMENTSTATUS = 'C' AND FCANCELSTATUS = 'A' AND FSTATUS IN ('2','3') ", new object[0]);
            listSelBillShowParameter.IsLookUp = true;
            listSelBillShowParameter.IsShowApproved = true;
            listSelBillShowParameter.IsShowFilter = false;
            listSelBillShowParameter.IsShowUsed = true;
            List<long> permissionOrg = PermissionServiceHelper.GetPermissionOrg(base.Context, new BusinessObject
            {
                Id = "SUB_SUBREQORDER"
            }, "6e44119a58cb4a8e86f6c385e14a17ad");
            permissionOrg.Add(0L);
            listSelBillShowParameter.MutilListUseOrgId = string.Join<long>(",", permissionOrg);
            listSelBillShowParameter.IsIsolationOrg = true;
            List<long> lstEntryids = null;
            this.View.ShowForm(listSelBillShowParameter, delegate (FormResult reusult)
            {
                this.listSelects = (reusult.ReturnData as ListSelectedRowCollection);
                if (this.listSelects != null && this.listSelects.Count > 0)
                {
                    lstEntryids = (from p in this.listSelects
                                   select Convert.ToInt64(p.EntryPrimaryKeyValue)).ToList<long>();
                    this.ShowSummaryOutsourcingData(lstEntryids);
                }
            });
        }

        [Obsolete]
        private void ShowSummaryOutsourcingData(List<long> lstEntryids)
        {
            if (lstEntryids.Count <= 0)
            {
                return;
            }
            DynamicObjectCollection summaryOutsourcingData = PurchaseNewServiceHelper.GetSummaryOutsourcingData(base.Context, lstEntryids);
            if (this.View.Model.GetEntryRowCount("FSummaryData") != 0)
            {
                this.View.Model.DeleteEntryData("FSummaryData");
            }
            int num = 0;
            foreach (DynamicObject dynamicObject in summaryOutsourcingData)
            {
                Entity entity = this.View.Model.BusinessInfo.GetEntity("FSummaryData");
                this.View.Model.CreateNewEntryRow(entity, num);
                this.View.Model.SetValue("FEntryId", Convert.ToInt64(dynamicObject["FENTRYID"]), num);
                this.View.Model.SetValue("FSaleOrgId", Convert.ToInt64(dynamicObject["FSUBORGID"]), num);
                this.View.Model.SetValue("FSalBillNo", Convert.ToString(dynamicObject["FBILLNO"]), num);
                this.View.Model.SetValue("FMaterialId", Convert.ToInt64(dynamicObject["FMATERIALID"]), num);
                this.View.Model.SetValue("FUnitID", Convert.ToInt64(dynamicObject["FUNITID"]), num);
                this.View.Model.SetValue("FQty", Convert.ToDecimal(dynamicObject["FQTY"]), num);
                this.View.Model.SetValue("FDeliveryDate", Convert.ToDateTime(dynamicObject["FPLANSTARTDATE"]), num);
                long num2 = Convert.ToInt64(dynamicObject["FBOMID"]);
                if (num2 <= 0L)
                {
                    DynamicObject dynamicObject2 = this.View.Model.GetValue("FMaterialId", num) as DynamicObject;
                    if (dynamicObject2 != null)
                    {
                        DynamicObject dynamicObject3 = (dynamicObject2["MaterialBase"] as DynamicObjectCollection)[0];
                        num2 = MFGServiceHelperForSCM.GetDefaultBomKey(base.Context, Convert.ToInt64(dynamicObject2[FormConst.MASTER_ID]), base.Context.CurrentOrganizationInfo.ID, Convert.ToInt32(dynamicObject3["ErpClsID"]));
                    }
                }
                this.View.Model.SetValue("FBomId", num2, num);
                this.View.Model.SetValue("FBaseUnitId", Convert.ToInt64(dynamicObject["FBASEUNITID"]), num);
                this.View.Model.SetValue("FBaseQty", Convert.ToDecimal(dynamicObject["FBASEUNITQTY"]), num);
                this.View.Model.SetValue("FHeadAuxpropId", Convert.ToInt64(dynamicObject["FAUXPROPID"]), num);
                num++;
            }
            this.View.UpdateView();
        }

        [Obsolete]
        private void GetPlanInfo()
        {
            ListSelBillShowParameter listSelBillShowParameter = new ListSelBillShowParameter();
            listSelBillShowParameter.FormId = "PLN_PLANORDER";
            listSelBillShowParameter.ParentPageId = this.View.PageId;
            listSelBillShowParameter.ListFilterParameter.Filter = string.Format(" FDOCUMENTSTATUS = 'C' AND FRELEASESTATUS IN ('0','1','2')", new object[0]);
            listSelBillShowParameter.IsLookUp = true;
            listSelBillShowParameter.IsShowFilter = false;
            listSelBillShowParameter.IsShowApproved = true;
            listSelBillShowParameter.IsShowUsed = true;
            List<long> permissionOrg = PermissionServiceHelper.GetPermissionOrg(base.Context, new BusinessObject
            {
                Id = "PLN_PLANORDER"
            }, "6e44119a58cb4a8e86f6c385e14a17ad");
            permissionOrg.Add(0L);
            listSelBillShowParameter.MutilListUseOrgId = string.Join<long>(",", permissionOrg);
            listSelBillShowParameter.IsIsolationOrg = true;
            List<long> lstEntryIds = null;
            this.View.ShowForm(listSelBillShowParameter, delegate (FormResult reusult)
            {
                this.listSelects = (reusult.ReturnData as ListSelectedRowCollection);
                if (this.listSelects != null && this.listSelects.Count > 0)
                {
                    lstEntryIds = (from p in this.listSelects
                                   select Convert.ToInt64(p.PrimaryKeyValue)).ToList<long>();
                    this.ShowSummaryPlanData(lstEntryIds);
                }
            });
        }

        [Obsolete]
        private void ShowSummaryPlanData(List<long> lstEntryids)
        {
            if (lstEntryids.Count <= 0)
            {
                return;
            }
            DynamicObjectCollection summaryPlanData = PurchaseNewServiceHelper.GetSummaryPlanData(base.Context, lstEntryids);
            if (this.View.Model.GetEntryRowCount("FSummaryData") != 0)
            {
                this.View.Model.DeleteEntryData("FSummaryData");
            }
            int num = 0;
            foreach (DynamicObject dynamicObject in summaryPlanData)
            {
                Entity entity = this.View.Model.BusinessInfo.GetEntity("FSummaryData");
                this.View.Model.CreateNewEntryRow(entity, num);
                this.View.Model.SetValue("FSaleOrgId", Convert.ToInt64(dynamicObject["FSUPPLYORGID"]), num);
                this.View.Model.SetValue("FSalBillNo", Convert.ToString(dynamicObject["FBILLNO"]), num);
                this.View.Model.SetValue("FMaterialId", Convert.ToInt64(dynamicObject["FMATERIALID"]), num);
                this.View.Model.SetValue("FUnitID", Convert.ToInt64(dynamicObject["FUNITID"]), num);
                this.View.Model.SetValue("FQty", Convert.ToDecimal(dynamicObject["FSUGQTY"]), num);
                this.View.Model.SetValue("FDeliveryDate", Convert.ToDateTime(dynamicObject["FPLANSTARTDATE"]), num);
                long num2 = Convert.ToInt64(dynamicObject["FBOMID"]);
                if (num2 <= 0L)
                {
                    DynamicObject dynamicObject2 = this.View.Model.GetValue("FMaterialId", num) as DynamicObject;
                    if (dynamicObject2 != null)
                    {
                        DynamicObject dynamicObject3 = (dynamicObject2["MaterialBase"] as DynamicObjectCollection)[0];
                        num2 = MFGServiceHelperForSCM.GetDefaultBomKey(base.Context, Convert.ToInt64(dynamicObject2[FormConst.MASTER_ID]), base.Context.CurrentOrganizationInfo.ID, Convert.ToInt32(dynamicObject3["ErpClsID"]));
                    }
                }
                this.View.Model.SetValue("FBomId", num2, num);
                this.View.Model.SetValue("FBaseUnitId", Convert.ToInt64(dynamicObject["FBASEUNITID"]), num);
                this.View.Model.SetValue("FBaseQty", Convert.ToDecimal(dynamicObject["FBASESUGQTY"]), num);
                this.View.Model.SetValue("FHeadAuxpropId", Convert.ToInt64(dynamicObject["FAUXPROPID"]), num);
                num++;
            }
            this.View.UpdateView();
        }

        [Obsolete]
        private void GetProduceInfo()
        {
            ListSelBillShowParameter listSelBillShowParameter = new ListSelBillShowParameter();
            listSelBillShowParameter.FormId = "PRD_MO";
            listSelBillShowParameter.ParentPageId = this.View.PageId;
            listSelBillShowParameter.ListFilterParameter.Filter = string.Format("FDOCUMENTSTATUS ='C' AND FCANCELSTATUS = 'A' AND FSTATUS IN ('2','3','4') ", new object[0]);
            listSelBillShowParameter.IsLookUp = true;
            listSelBillShowParameter.IsShowApproved = true;
            listSelBillShowParameter.IsShowFilter = false;
            listSelBillShowParameter.IsShowUsed = true;
            List<long> permissionOrg = PermissionServiceHelper.GetPermissionOrg(base.Context, new BusinessObject
            {
                Id = "PRD_MO"
            }, "6e44119a58cb4a8e86f6c385e14a17ad");
            permissionOrg.Add(0L);
            listSelBillShowParameter.MutilListUseOrgId = string.Join<long>(",", permissionOrg);
            listSelBillShowParameter.IsIsolationOrg = true;
            List<long> lstEntryids = null;
            this.View.ShowForm(listSelBillShowParameter, delegate (FormResult reusult)
            {
                this.listSelects = (reusult.ReturnData as ListSelectedRowCollection);
                if (this.listSelects != null && this.listSelects.Count > 0)
                {
                    lstEntryids = (from p in this.listSelects
                                   select Convert.ToInt64(p.EntryPrimaryKeyValue)).ToList<long>();
                    this.ShowSummaryProduceData(lstEntryids);
                }
            });
        }

        [Obsolete]
        private void ShowSummaryProduceData(List<long> lstEntryids)
        {
            if (lstEntryids.Count <= 0)
            {
                return;
            }
            DynamicObjectCollection summaryProduceData = PurchaseNewServiceHelper.GetSummaryProduceData(base.Context, lstEntryids);
            if (this.View.Model.GetEntryRowCount("FSummaryData") != 0)
            {
                this.View.Model.DeleteEntryData("FSummaryData");
            }
            int num = 0;
            foreach (DynamicObject dynamicObject in summaryProduceData)
            {
                Entity entity = this.View.Model.BusinessInfo.GetEntity("FSummaryData");
                this.View.Model.CreateNewEntryRow(entity, num);
                this.View.Model.SetValue("FEntryId", Convert.ToInt64(dynamicObject["FENTRYID"]), num);
                this.View.Model.SetValue("FSaleOrgId", Convert.ToInt64(dynamicObject["FPRDORGID"]), num);
                this.View.Model.SetValue("FSalBillNo", Convert.ToString(dynamicObject["FBILLNO"]), num);
                this.View.Model.SetValue("FMaterialId", Convert.ToInt64(dynamicObject["FMATERIALID"]), num);
                this.View.Model.SetValue("FUnitID", Convert.ToInt64(dynamicObject["FUNITID"]), num);
                this.View.Model.SetValue("FQty", Convert.ToDecimal(dynamicObject["FQTY"]), num);
                this.View.Model.SetValue("FDeliveryDate", Convert.ToDateTime(dynamicObject["FPLANSTARTDATE"]), num);
                long num2 = Convert.ToInt64(dynamicObject["FBOMID"]);
                if (num2 <= 0L)
                {
                    DynamicObject dynamicObject2 = this.View.Model.GetValue("FMaterialId", num) as DynamicObject;
                    if (dynamicObject2 != null)
                    {
                        DynamicObject dynamicObject3 = (dynamicObject2["MaterialBase"] as DynamicObjectCollection)[0];
                        num2 = MFGServiceHelperForSCM.GetDefaultBomKey(base.Context, Convert.ToInt64(dynamicObject2[FormConst.MASTER_ID]), base.Context.CurrentOrganizationInfo.ID, Convert.ToInt32(dynamicObject3["ErpClsID"]));
                    }
                }
                this.View.Model.SetValue("FBomId", num2, num);
                this.View.Model.SetValue("FBaseUnitId", Convert.ToInt64(dynamicObject["FBASEUNITID"]), num);
                this.View.Model.SetValue("FBaseQty", Convert.ToDecimal(dynamicObject["FBASEUNITQTY"]), num);
                this.View.Model.SetValue("FHeadAuxpropId", Convert.ToInt64(dynamicObject["FAUXPROPID"]), num);
                num++;
            }
            this.View.UpdateView();
        }

        [Obsolete]
        private void GetPredictInfo()
        {
            ListSelBillShowParameter listSelBillShowParameter = new ListSelBillShowParameter();
            listSelBillShowParameter.FormId = "PLN_FORECAST";
            listSelBillShowParameter.ParentPageId = this.View.PageId;
            listSelBillShowParameter.ListFilterParameter.Filter = string.Format(" FDOCUMENTSTATUS ='C' AND FCANCELSTATUS = 'A' AND FCLOSESTATUS = 'A'", new object[0]);
            listSelBillShowParameter.IsLookUp = true;
            listSelBillShowParameter.IsShowFilter = false;
            listSelBillShowParameter.IsShowApproved = true;
            listSelBillShowParameter.IsShowUsed = true;
            List<long> permissionOrg = PermissionServiceHelper.GetPermissionOrg(base.Context, new BusinessObject
            {
                Id = "PLN_FORECAST"
            }, "6e44119a58cb4a8e86f6c385e14a17ad");
            permissionOrg.Add(0L);
            listSelBillShowParameter.MutilListUseOrgId = string.Join<long>(",", permissionOrg);
            listSelBillShowParameter.IsIsolationOrg = true;
            List<long> lstEntryids = null;
            this.View.ShowForm(listSelBillShowParameter, delegate (FormResult reusult)
            {
                this.listSelects = (reusult.ReturnData as ListSelectedRowCollection);
                if (this.listSelects != null && this.listSelects.Count > 0)
                {
                    lstEntryids = (from p in this.listSelects
                                   select Convert.ToInt64(p.EntryPrimaryKeyValue)).ToList<long>();
                    this.ShowSummaryPredictData(lstEntryids);
                }
            });
        }

        [Obsolete]
        private void ShowSummaryPredictData(List<long> lstEntryids)
        {
            if (lstEntryids.Count <= 0)
            {
                return;
            }
            DynamicObjectCollection summaryPredictData = PurchaseNewServiceHelper.GetSummaryPredictData(base.Context, lstEntryids);
            if (this.View.Model.GetEntryRowCount("FSummaryData") > 0)
            {
                this.View.Model.DeleteEntryData("FSummaryData");
            }
            int num = 0;
            foreach (DynamicObject dynamicObject in summaryPredictData)
            {
                Entity entity = this.View.Model.BusinessInfo.GetEntity("FSummaryData");
                this.View.Model.CreateNewEntryRow(entity, num);
                this.View.Model.SetValue("FEntryId", Convert.ToInt64(dynamicObject["FENTRYID"]), num);
                this.View.Model.SetValue("FSaleOrgId", Convert.ToInt64(dynamicObject["FFOREORGID"]), num);
                this.View.Model.SetValue("FSalBillNo", Convert.ToString(dynamicObject["FBILLNO"]), num);
                this.View.Model.SetValue("FMaterialId", Convert.ToInt64(dynamicObject["FMATERIALID"]), num);
                this.View.Model.SetValue("FCustId", Convert.ToInt64(dynamicObject["FCUSTID"]), num);
                this.View.Model.SetValue("FUnitID", Convert.ToInt64(dynamicObject["FUNITID"]), num);
                this.View.Model.SetValue("FQty", Convert.ToDecimal(dynamicObject["FQTY"]), num);
                this.View.Model.SetValue("FDeliveryDate", Convert.ToDateTime(dynamicObject["FSTARTDATE"]), num);
                long num2 = Convert.ToInt64(dynamicObject["FBOMID"]);
                if (num2 <= 0L)
                {
                    DynamicObject dynamicObject2 = this.View.Model.GetValue("FMaterialID", num) as DynamicObject;
                    if (dynamicObject2 != null)
                    {
                        DynamicObject dynamicObject3 = (dynamicObject2["MaterialBase"] as DynamicObjectCollection)[0];
                        num2 = MFGServiceHelperForSCM.GetDefaultBomKey(base.Context, Convert.ToInt64(dynamicObject2[FormConst.MASTER_ID]), base.Context.CurrentOrganizationInfo.ID, Convert.ToInt32(dynamicObject3["ErpClsID"]));
                    }
                }
                this.View.Model.SetValue("FBomId", num2, num);
                this.View.Model.SetValue("FBaseUnitId", Convert.ToInt64(dynamicObject["FBASEUNITID"]), num);
                this.View.Model.SetValue("FBaseQty", Convert.ToDecimal(dynamicObject["FBASEQTY"]), num);
                this.View.Model.SetValue("FHeadAuxpropId", Convert.ToInt64(dynamicObject["FAUXPROPID"]), num);
                num++;
            }
            this.View.UpdateView();
        }

        [Obsolete]
        private void GetSalOrderInfo()
        {
            ListSelBillShowParameter listSelBillShowParameter = new ListSelBillShowParameter();
            listSelBillShowParameter.FormId = "SAL_SaleOrder";
            listSelBillShowParameter.ParentPageId = this.View.PageId;
            listSelBillShowParameter.ListFilterParameter.Filter = string.Format(" FDOCUMENTSTATUS = 'C' AND FCANCELSTATUS = 'A' AND FCLOSESTATUS = 'A' ", new object[0]);
            listSelBillShowParameter.IsLookUp = true;
            listSelBillShowParameter.IsShowFilter = false;
            listSelBillShowParameter.IsShowApproved = true;
            listSelBillShowParameter.IsShowUsed = true;
            List<long> permissionOrg = PermissionServiceHelper.GetPermissionOrg(base.Context, new BusinessObject
            {
                Id = "SAL_SaleOrder"
            }, "6e44119a58cb4a8e86f6c385e14a17ad");
            permissionOrg.Add(0L);
            listSelBillShowParameter.MutilListUseOrgId = string.Join<long>(",", permissionOrg);
            listSelBillShowParameter.IsIsolationOrg = true;
            List<long> lstEntryIds = null;
            this.View.ShowForm(listSelBillShowParameter, delegate (FormResult reusult)
            {
                this.listSelects = (reusult.ReturnData as ListSelectedRowCollection);
                if (this.listSelects != null && this.listSelects.Count > 0)
                {
                    lstEntryIds = (from p in this.listSelects
                                   select Convert.ToInt64(p.EntryPrimaryKeyValue)).ToList<long>();
                    this.ShowSummaryData(lstEntryIds);
                }
            });
        }

        [Obsolete]
        private void ShowSummaryData(List<long> lstEntryids)
        {
            if (lstEntryids.Count <= 0)
            {
                return;
            }
            DynamicObjectCollection summarySalData = PurchaseServiceHelper.GetSummarySalData(this.Context, lstEntryids);
            if (this.View.Model.GetEntryRowCount("FSummaryData") != 0)
            {
                this.View.Model.DeleteEntryData("FSummaryData");
            }
            int num = 0;
            foreach (DynamicObject dynamicObject in summarySalData)
            {
                Entity entity = this.View.BusinessInfo.GetEntity("FSummaryData");
                this.View.Model.CreateNewEntryRow(entity, num);
                this.View.Model.SetValue("FEntryId", Convert.ToInt64(dynamicObject["FENTRYID"]), num);
                this.View.Model.SetValue("FSaleOrgId", Convert.ToInt64(dynamicObject["FSALEORGID"]), num);
                this.View.Model.SetValue("FSalBillNo", Convert.ToString(dynamicObject["FBILLNO"]), num);
                this.View.Model.SetValue("FMaterialId", Convert.ToInt64(dynamicObject["FMATERIALID"]), num);
                this.View.Model.SetValue("FCustId", Convert.ToInt64(dynamicObject["FCUSTID"]), num);
                this.View.Model.SetValue("FUnitId", Convert.ToInt64(dynamicObject["FUNITID"]), num);
                this.View.Model.SetValue("FQty", Convert.ToDecimal(dynamicObject["FQTY"]), num);
                this.View.Model.SetValue("FDeliveryDate", Convert.ToDateTime(dynamicObject["FDELIVERYDATE"]), num);
                this.View.Model.SetValue("FSupplyOrgId", Convert.ToInt64(dynamicObject["FSUPPLYORGID"]), num);
                long num2 = 0L;
                long num3 = Convert.ToInt64(dynamicObject["FBOMID"]);
                DynamicObject dynamicObject2 = this.View.Model.GetValue("FMaterialId", num) as DynamicObject;
                if (dynamicObject2 != null)
                {
                    DynamicObject dynamicObject3 = (dynamicObject2["MaterialBase"] as DynamicObjectCollection)[0];
                    num2 = MFGServiceHelperForSCM.GetDefaultBomKey(base.Context, Convert.ToInt64(dynamicObject2[FormConst.MASTER_ID]), Convert.ToInt64(dynamicObject["FSUPPLYORGID"]), Convert.ToInt32(dynamicObject3["ErpClsID"]));
                    if (num3 <= 0L)
                    {
                        num3 = MFGServiceHelperForSCM.GetDefaultBomKey(base.Context, Convert.ToInt64(dynamicObject2[FormConst.MASTER_ID]), base.Context.CurrentOrganizationInfo.ID, Convert.ToInt32(dynamicObject3["ErpClsID"]));
                    }
                }
                this.View.Model.SetValue("FBomId", num3, num);
                this.View.Model.SetValue("FSupplyOrgBomId", num2, num);
                this.View.Model.SetValue("FBaseUnitId", Convert.ToInt64(dynamicObject["FBASEUNITID"]), num);
                this.View.Model.SetValue("FBaseQty", Convert.ToDecimal(dynamicObject["FBASEUNITQTY"]), num);
                this.View.Model.SetValue("FHeadAuxpropId", Convert.ToInt64(dynamicObject["FAUXPROPID"]), num);
                num++;
            }
            this.View.UpdateView();
        }

        private void ShowAssortCalaGrid(bool isVisible)
        {
            this.View.GetControl<SplitContainer>("FSpliteContainer").HideSecondPanel(!isVisible);
            this.bShowAssortResult = isVisible;
        }

        private bool bShowAssortResult;
        private ProgressBar _progressBar;
        private int _processRate;
        private string _processTips;
        private ListSelectedRowCollection listSelects;
        private bool bChkSupplyOrgBom;
        private bool isCalculated;
        private FormMetadata _PurRequisitionListMeta;
        private Dictionary<long, Kingdee.K3.Core.MFG.EnumConst.Enums.Enu_BomExpandCalType> orgBomExpandCalTypeDics = new Dictionary<long, Kingdee.K3.Core.MFG.EnumConst.Enums.Enu_BomExpandCalType>();
        private bool flag;
        private object _lockObject = new object();

        private long ReqOrgId
        {
            get
            {
                DynamicObject dynamicObject = this.View.Model.GetValue("FApplicationOrgId") as DynamicObject;
                if (dynamicObject != null)
                {
                    return Convert.ToInt64(dynamicObject["Id"]);
                }
                throw new Exception(ResManager.LoadKDString("请先选择申请组织", "004015000017483", SubSystemType.SCM, new object[0]));
            }
        }

        private bool IsSpoilage
        {
            get
            {
                return Convert.ToBoolean(this.View.Model.GetValue("FIsSpoilage"));
            }
        }

        private bool isAllowMRP
        {
            get
            {
                return Convert.ToBoolean(this.View.Model.GetValue("FIsAllowMRP"));
            }
        }

        private bool IsAuxProp
        {
            get
            {
                return Convert.ToBoolean(this.View.Model.GetValue("FIsAuxProp"));
            }
        }

        private bool IsSafeStock
        {
            get
            {
                return Convert.ToBoolean(this.View.Model.GetValue("FIsSafeStock"));
            }
        }
    }
}
